/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package partie3;

import java.io.*;
import java.net.*;

/**
 *
 * @author Hugo
 */
public class Client {
    private InetAddress hostname;
    private int port;
    private DatagramSocket socketClient ;

    public Client(InetAddress hostname, int port)
    {
        this.hostname = hostname;
        this.port = port;
    }
    
    public void connect() throws UnknownHostException, IOException{
        System.out.println("Attempting to connect to "+hostname+":"+port);
        //socketClient = new DatagramSocket();
        byte[] data = new byte[256];
        try{
            DatagramPacket packet = new DatagramPacket(data, data.length, hostname, port);
            socketClient.send(packet);
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    
//    public boolean readResponse() throws IOException{
//        OutputStreamWriter writer = new OutputStreamWriter(new BufferedOutputStream(socketClient.getOutputStream()));
//        
//        String line = "";
//        while (true)
//        { 
//            System.out.print("client > ");
//            line = new BufferedReader(new InputStreamReader(System.in)).readLine();
//
//            writer.write(line + (char) 13);
//            writer.flush();
//            
//            if (line.toLowerCase().equals("exit"))
//                break;
//        }
//        
//        writer.close();
//        return false;
//    }
    
    public static void main(String[] args) 
    {
        try 
        {
            Client client = new Client (InetAddress.getByName("127.0.0.1"),8080);
            //trying to establish connection to the server
            client.connect();
            
            //if successful, read response from server
//            while(true)
//                client.readResponse();
            
        } 
        catch (UnknownHostException e) 
        {
            System.out.println("Host unknown. Cannot establish connection");
        } 
        catch (IOException e) 
        {
            System.out.println("Cannot establish connection. Server may not be up. "+e.getMessage());
        }
    }
    
}
